package com.ruoyi.web.controller.business;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.business.domain.*;
import com.ruoyi.business.service.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessStatus;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.system.domain.SysOperLog;
import com.ruoyi.system.service.ISysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

@RestController
@RequestMapping("/manager")
@Api(value = "公共api", description = "公共api",tags = "公共api")
public class ManagerController extends BaseController {

    @Autowired
    private IAchievementAwardsService achievementAwardsService;

    @Autowired
    private IAnnualPlanWorkService annualPlanWorkService;

    @Autowired
    private IAnnualWorkDaysService annualWorkDaysService;

    @Autowired
    private IEmployeeAwardsInfoService employeeAwardsInfoService;

    @Autowired
    private IEmployeeInfoService employeeInfoService;

    @Autowired
    private IEmployeePerformanceService employeePerformanceService;

    @Autowired
    private IEmployeeTrainingService employeeTrainingService;

    @Autowired
    private IPapersAndBooksService papersAndBooksService;

    @Autowired
    private ITaskInfoService taskInfoService;

    @Autowired
    private ITrainingRecordService trainingRecordService;

    @Autowired
    private IWorkTicketInfoService workTicketInfoService;

    @Autowired
    private ImanagerService managerService;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private ISysOperLogService operLogService;

    @Autowired
    private IIndicatorOneService indicatorOneService;

    @Autowired
    private IIndicatorTowService indicatorTowService;

    @Autowired
    private IIndicatorThreeService indicatorThreeService;

    @Autowired
    private IIndicatorFourService indicatorFourService;

    @Autowired
    private IIndicatorFiveService indicatorFiveService;

    @Autowired
    private IIndicatorSixService indicatorSixService;

    /**
     * 返回这些员工基本信息
     *
     * 个人荣誉
     *
     * 培训授课记录
     *
     * 员工培训记录
     *
     * 工作票
     *
     * 年度绩效
     *
     * 重点工作任务
     *
     * 年度工作计划
     *
     * 成果获奖
     *
     * 全年出班天数
     *
     * 论文著作  按钮，并且携带每个按钮的上传接口地址和上传模版地址，还有按钮的名称
     */
    @GetMapping("/buttons")
    @ApiOperation(value = "获取员工相关信息按钮", notes = "返回包含员工基本信息、个人荣誉、培训授课记录等按钮信息的JSON响应")
    public AjaxResult getEmployeeInfo() {
        // 创建按钮信息列表
        List<ButtonInfo> buttons = new ArrayList<>();

        List<AchievementAwards> list1 = achievementAwardsService.selectAchievementAwardsList(new AchievementAwards());
        List<AnnualPlanWork> list2 = annualPlanWorkService.selectAnnualPlanWorkList(new AnnualPlanWork());
//        List<AnnualWorkDays> list3 = annualWorkDaysService.selectAnnualWorkDaysList(new AnnualWorkDays());
        List<EmployeeAwardsInfo> list4 = employeeAwardsInfoService.selectEmployeeAwardsInfoList(new EmployeeAwardsInfo());
        List<EmployeeInfo> list5 = employeeInfoService.selectEmployeeInfoList(new EmployeeInfo());
        List<EmployeePerformance> list6 = employeePerformanceService.selectEmployeePerformanceList(new EmployeePerformance());
        List<EmployeeTraining> list7 = employeeTrainingService.selectEmployeeTrainingList(new EmployeeTraining());
        List<PapersAndBooks> list8 = papersAndBooksService.selectPapersAndBooksList(new PapersAndBooks());
//        List<TaskInfo> list9 = taskInfoService.selectTaskInfoList(new TaskInfo());
        List<TrainingRecord> list10 = trainingRecordService.selectTrainingRecordList(new TrainingRecord());
//        List<WorkTicketInfo> list11 = workTicketInfoService.selectWorkTicketInfoList(new WorkTicketInfo());

        List<IndicatorOne> list12 = indicatorOneService.selectIndicatorOneList(new IndicatorOne());
        List<IndicatorTow> list13 = indicatorTowService.selectIndicatorTowList(new IndicatorTow());
        List<IndicatorThree> list14 = indicatorThreeService.selectIndicatorThreeList(new IndicatorThree());
        List<IndicatorFour> list15 = indicatorFourService.selectIndicatorFourList(new IndicatorFour());
        List<IndicatorFive> list16 = indicatorFiveService.selectIndicatorFiveList(new IndicatorFive());
        List<IndicatorSix> list17 = indicatorSixService.selectIndicatorSixList(new IndicatorSix());

        buttons.add(new ButtonInfo("员工基本信息", "/business/employeeInfo/importData", "/business/employeeInfo/importTemplate",list5.size()>0?true:false));
        buttons.add(new ButtonInfo("个人荣誉", "/business/employeeAwardsInfo/importData", "/business/employeeAwardsInfo/importTemplate",list4.size()>0?true:false));
        buttons.add(new ButtonInfo("培训授课记录", "/business/TrainingRecord/importData", "/business/TrainingRecord/importTemplate",list10.size()>0?true:false));
        buttons.add(new ButtonInfo("员工培训记录", "/business/training/importData", "/business/training/importTemplate",list7.size()>0?true:false));
//        buttons.add(new ButtonInfo("工作票", "/business/workTicketInfo/importData", "/business/workTicketInfo/importTemplate",list11.size()>0?true:false));
        buttons.add(new ButtonInfo("年度绩效", "/business/performance/importData", "/business/performance/importTemplate",list6.size()>0?true:false));
//        buttons.add(new ButtonInfo("重点工作任务", "/business/TaskInfo/importData", "/business/TaskInfo/importTemplate",list9.size()>0?true:false));
        buttons.add(new ButtonInfo("年度工作计划", "/business/work/importData", "/business/work/importTemplate",list2.size()>0?true:false));
        buttons.add(new ButtonInfo("成果获奖", "/business/awards/importData", "/business/awards/importTemplate",list1.size()>0?true:false));
//        buttons.add(new ButtonInfo("全年出班天数", "/business/days/importData", "/business/days/importTemplate",list3.size()>0?true:false));
        buttons.add(new ButtonInfo("论文著作", "/business/papersAndBooks/importData", "/business/papersAndBooks/importTemplate",list8.size()>0?true:false));

        buttons.add(new ButtonInfo("指标一", "/business/indicatorOne/importData", "/business/indicatorOne/importTemplate",list12.size()>0?true:false));
        buttons.add(new ButtonInfo("指标二", "/business/indicatorTow/importData", "/business/indicatorTow/importTemplate",list13.size()>0?true:false));
        buttons.add(new ButtonInfo("指标三", "/business/indicatorThree/importData", "/business/indicatorThree/importTemplate",list14.size()>0?true:false));
        buttons.add(new ButtonInfo("指标四", "/business/indicatorFour/importData", "/business/indicatorFour/importTemplate",list15.size()>0?true:false));
        buttons.add(new ButtonInfo("指标五", "/business/indicatorFive/importData", "/business/indicatorFive/importTemplate",list16.size()>0?true:false));
        buttons.add(new ButtonInfo("指标六", "/business/indicatorSix/importData", "/business/indicatorSix/importTemplate",list17.size()>0?true:false));

        // 创建响应对象
        return success(buttons);
    }

    /**
     * 导出所有模板 输出一个zip压缩包
     */
    @PostMapping("/exportAllTemplate")
    @ApiOperation(value = "导出所有模板", notes = "导出所有模板")
    public void exportAllTemplate(HttpServletResponse response) {
        File tempDir = new File(System.getProperty("java.io.tmpdir"), "exportTemplates");
        if (!tempDir.exists()) {
            tempDir.mkdirs();
        }

        try {
            exportTemplates(new ExcelUtil<>(EmployeeInfo.class), "员工数据", tempDir);
            exportTemplates(new ExcelUtil<>(AchievementAwards.class), "成果获奖数据", tempDir);
            exportTemplates(new ExcelUtil<>(AnnualPlanWork.class), "年度计划工作数据", tempDir);
            exportTemplates(new ExcelUtil<>(EmployeeAwardsInfo.class), "个人荣誉数据", tempDir);
            exportTemplates(new ExcelUtil<>(EmployeePerformance.class), "员工年度绩效数据", tempDir);
            exportTemplates(new ExcelUtil<>(EmployeeTraining.class), "员工培训记录数据", tempDir);
            exportTemplates(new ExcelUtil<>(PapersAndBooks.class), "论文著作数据", tempDir);
            exportTemplates(new ExcelUtil<>(TrainingRecord.class), "培训授课记录", tempDir);

            exportTemplates(new ExcelUtil<>(IndicatorOne.class), "指标数据一", tempDir);
            exportTemplates(new ExcelUtil<>(IndicatorTow.class), "指标数据二", tempDir);
            exportTemplates(new ExcelUtil<>(IndicatorThree.class), "指标数据三", tempDir);
            exportTemplates(new ExcelUtil<>(IndicatorFour.class), "指标数据四", tempDir);
            exportTemplates(new ExcelUtil<>(IndicatorFive.class), "指标数据五", tempDir);
            exportTemplates(new ExcelUtil<>(IndicatorSix.class), "指标数据六", tempDir);

            File zipFile = new File(tempDir.getParent(), "templates.zip");
            zipFiles(tempDir, zipFile);

            response.setContentType("application/zip");
            response.setHeader("Content-Disposition", "attachment; filename=templates.zip");
            try (FileInputStream fis = new FileInputStream(zipFile);
                 ServletOutputStream sos = response.getOutputStream()) {
                byte[] buffer = new byte[1024];
                int length;
                while ((length = fis.read(buffer)) >= 0) {
                    sos.write(buffer, 0, length);
                }
            }

            // 删除临时文件和目录
            deleteDirectory(tempDir);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void exportTemplates(ExcelUtil<?> util, String sheetName, File tempDir) throws IOException {
        File file = new File(tempDir, sheetName + ".xlsx");
        util.importTemplateExcel(file, sheetName,sheetName);
    }

    private void zipFiles(File directoryToZip, File zipFile) throws IOException {
        try (FileOutputStream fos = new FileOutputStream(zipFile);
             ZipOutputStream zos = new ZipOutputStream(fos)) {
            File[] files = directoryToZip.listFiles();
            if (files != null) {
                for (File file : files) {
                    zip(file, file.getName(), zos);
                }
            }
        }
    }

    private void zip(File fileToZip, String fileName, ZipOutputStream zos) throws IOException {
        if (fileToZip.isHidden()) {
            return;
        }
        if (fileToZip.isDirectory()) {
            if (fileName.endsWith("/")) {
                zos.putNextEntry(new ZipEntry(fileName));
                zos.closeEntry();
            } else {
                zos.putNextEntry(new ZipEntry(fileName + "/"));
                zos.closeEntry();
            }
            File[] children = fileToZip.listFiles();
            if (children != null) {
                for (File childFile : children) {
                    zip(childFile, childFile.getName(), zos);
                }
            }
            return;
        }
        try (FileInputStream fis = new FileInputStream(fileToZip)) {
            ZipEntry zipEntry = new ZipEntry(fileName);
            zos.putNextEntry(zipEntry);
            byte[] bytes = new byte[1024];
            int length;
            while ((length = fis.read(bytes)) >= 0) {
                zos.write(bytes, 0, length);
            }
        }
    }

    private void deleteDirectory(File directoryToBeDeleted) {
        File[] allContents = directoryToBeDeleted.listFiles();
        if (allContents != null) {
            for (File file : allContents) {
                deleteDirectory(file);
            }
        }
        directoryToBeDeleted.delete();
    }


    /**
     * 清空数据
     */
    @GetMapping("/clear")
    @ApiOperation(value = "清空数据", notes = "清空所有数据")
    public AjaxResult clear() {

        if (redisCache.getCacheObject("lock-data") != null) {
            return warn("正在重跑，请勿删除操作");
        }

        managerService.clear();

        // 获取当前的用户
        LoginUser loginUser = SecurityUtils.getLoginUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setTitle("数据管理");
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = IpUtils.getIpAddr();
        operLog.setOperIp(ip);
        operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
        if (loginUser != null)
        {
            operLog.setOperName(loginUser.getUsername());
            SysUser currentUser = loginUser.getUser();
            if (StringUtils.isNotNull(currentUser) && StringUtils.isNotNull(currentUser.getDept()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }
        // 设置方法名称
        operLog.setMethod("edit");
        // 设置请求方式
        operLog.setRequestMethod(ServletUtils.getRequest().getMethod());

        // 处理设置注解上的参数
        String template = String.format("数据管理，清空全部数据。");
        operLog.setJsonResult(template);
        // 设置消耗时间
        operLog.setCostTime(0L);

        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));

        return success("清空成功");
    }

    /**
     * 本年度数据重跑
     */
    @GetMapping("/reRun")
    @ApiOperation(value = "年度数据重跑", notes = "重跑所有数据")
    public AjaxResult reRun() {

        if (redisCache.getCacheObject("lock-data") != null) {
            return warn("正在重跑，请勿重复操作");
        }

        redisCache.setCacheObject("lock-data", true, 30, TimeUnit.MINUTES);

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH, Calendar.JANUARY);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date awd = calendar.getTime();

        managerService.reRun(awd);
        redisCache.deleteObject("lock-data");
        redisCache.setCacheObject("run-date", new Date());

        // 获取当前的用户
        LoginUser loginUser = SecurityUtils.getLoginUser();
        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setTitle("数据管理");
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = IpUtils.getIpAddr();
        operLog.setOperIp(ip);
        operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
        if (loginUser != null)
        {
            operLog.setOperName(loginUser.getUsername());
            SysUser currentUser = loginUser.getUser();
            if (StringUtils.isNotNull(currentUser) && StringUtils.isNotNull(currentUser.getDept()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }
        // 设置方法名称
        operLog.setMethod("edit");
        // 设置请求方式
        operLog.setRequestMethod(ServletUtils.getRequest().getMethod());

        // 处理设置注解上的参数
        String template = String.format("数据管理，跑本年度数据。");
        operLog.setJsonResult(template);
        // 设置消耗时间
        operLog.setCostTime(0L);

        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));


        return success("重跑成功");
    }

    /**
     * 全部数据重跑
     */
    @GetMapping("/reRunAll")
    @ApiOperation(value = "全部数据重跑", notes = "重跑所有数据")
    public AjaxResult reRunAll() {

        if (redisCache.getCacheObject("lock-data") != null) {
            return warn("正在重跑，请勿重复操作");
        }

        redisCache.setCacheObject("lock-data", true, 30, TimeUnit.MINUTES);

        managerService.reRunAll();

        redisCache.deleteObject("lock-data");
        redisCache.setCacheObject("run-date", new Date());

        // 获取当前的用户
        LoginUser loginUser = SecurityUtils.getLoginUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setTitle("数据管理");
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = IpUtils.getIpAddr();
        operLog.setOperIp(ip);
        operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
        if (loginUser != null)
        {
            operLog.setOperName(loginUser.getUsername());
            SysUser currentUser = loginUser.getUser();
            if (StringUtils.isNotNull(currentUser) && StringUtils.isNotNull(currentUser.getDept()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }
        // 设置方法名称
        operLog.setMethod("edit");
        // 设置请求方式
        operLog.setRequestMethod(ServletUtils.getRequest().getMethod());

        // 处理设置注解上的参数
        String template = String.format("数据管理，跑全部数据。");
        operLog.setJsonResult(template);
        // 设置消耗时间
        operLog.setCostTime(0L);

        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));

        return success("重跑成功");
    }


    @GetMapping("/getDataStatus")
    @ApiOperation(value = "跑数状态", notes = "跑数状态")
    public AjaxResult getDataStatus() {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",redisCache.hasKey("lock-data")?"跑数中":"");
        jsonObject.put("updateTime",redisCache.getCacheObject("run-date"));

        JSONObject json = redisCache.getCacheObject("run-info-msg");
        if (json == null){
            jsonObject.put("runInfoTable","");
            jsonObject.put("runInfoSuccess","");
            jsonObject.put("runInfofail","");
            jsonObject.put("runInfoNum","");
        }else {
            jsonObject.put("runInfoTable",json.get("runInfoTable"));
            jsonObject.put("runInfoSuccess",json.get("runInfoSuccess"));
            jsonObject.put("runInfofail",json.get("runInfofail"));
            jsonObject.put("runInfoNum",json.get("runInfoNum"));
        }


        return success(jsonObject);
    }

    /**
     * 获取跑数年份列表
     *
     */
    @GetMapping("/getYearList")
    @ApiOperation(value = "获取跑数年份", notes = "获取跑数年份")
    public AjaxResult getYearList() {

        List<Date> years = managerService.getYearList();
        return success(years);
    }

    /**
     * 跑指定年份的数据
     */
    /** 数据管理
     * 跑指定年份的数据
     */
    @GetMapping("/reRunYear")
    @ApiOperation(value = "跑指定年份的数据", notes = "跑指定年份的数据")
    public AjaxResult reRunYear(@RequestParam String year) {

        if (redisCache.getCacheObject("lock-data") != null) {
            return warn("正在重跑，请勿重复操作");
        }

        redisCache.setCacheObject("lock-data", true, 30, TimeUnit.MINUTES);

        try {
            // 假设输入的日期字符串格式为 "yyyy"
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
            Date date = dateFormat.parse(year);

            managerService.reRun(date);
            redisCache.deleteObject("lock-data");
            redisCache.setCacheObject("run-date", new Date());

            // 获取当前的用户
            LoginUser loginUser = SecurityUtils.getLoginUser();

            // *========数据库日志=========*//
            SysOperLog operLog = new SysOperLog();
            operLog.setTitle("数据管理");
            operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
            // 请求的地址
            String ip = IpUtils.getIpAddr();
            operLog.setOperIp(ip);
            operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
            if (loginUser != null)
            {
                operLog.setOperName(loginUser.getUsername());
                SysUser currentUser = loginUser.getUser();
                if (StringUtils.isNotNull(currentUser) && StringUtils.isNotNull(currentUser.getDept()))
                {
                    operLog.setDeptName(currentUser.getDept().getDeptName());
                }
            }
            // 设置方法名称
            operLog.setMethod("edit");
            // 设置请求方式
            operLog.setRequestMethod(ServletUtils.getRequest().getMethod());

            // 处理设置注解上的参数
            String template = String.format("数据管理，跑%s年度数据。",year);
            operLog.setJsonResult(template);
            // 设置消耗时间
            operLog.setCostTime(0L);

            AsyncManager.me().execute(AsyncFactory.recordOper(operLog));

            return success("重跑成功");
        } catch (ParseException e) {
            redisCache.deleteObject("lock-data");
            return error("日期格式错误，请输入正确的年份格式 (yyyy)");
        }
    }

    /**
     * 清空数据
     */
    @GetMapping("/clearYear")
    @ApiOperation(value = "清空指定年份数据", notes = "清空指定年份数据")
    public AjaxResult clearYear(@RequestParam String year) {

        if (redisCache.getCacheObject("lock-data") != null) {
            return warn("正在重跑，请勿删除操作");
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
        Date date = null;
        try {
            date = dateFormat.parse(year);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        managerService.clear(date);

        // 获取当前的用户
        LoginUser loginUser = SecurityUtils.getLoginUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setTitle("数据管理");
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = IpUtils.getIpAddr();
        operLog.setOperIp(ip);
        operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
        if (loginUser != null)
        {
            operLog.setOperName(loginUser.getUsername());
            SysUser currentUser = loginUser.getUser();
            if (StringUtils.isNotNull(currentUser) && StringUtils.isNotNull(currentUser.getDept()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }
        // 设置方法名称
        operLog.setMethod("edit");
        // 设置请求方式
        operLog.setRequestMethod(ServletUtils.getRequest().getMethod());

        // 处理设置注解上的参数
        String template = String.format("数据管理，清空%s年度数据。",year);
        operLog.setJsonResult(template);
        // 设置消耗时间
        operLog.setCostTime(0L);

        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));

        return success("清空成功");
    }

    @GetMapping("/logList")
    @ApiOperation(value = "获取操作日志", notes = "获取操作日志")
    public TableDataInfo logList()
    {
        startPage();
        List<SysOperLog> list = operLogService.logList();
        return getDataTable(list);
    }

    @GetMapping("/getIndicatorRemark")
    @ApiOperation(value = "获取指标备注信息", notes = "获取指标备注信息")
    public R<String> getIndicatorRemark()
    {
        if(redisCache.hasKey("IndicatorRemarkKey")){
            return R.ok(redisCache.getCacheObject("IndicatorRemarkKey"));
        }else {
            return R.ok("暂无指标备注信息");
        }
    }

    @GetMapping("/setIndicatorRemark")
    @ApiOperation(value = "设置指标备注信息", notes = "设置指标备注信息")
    public R setIndicatorRemark(@RequestParam String remark)
    {
        String old = "";
        if(redisCache.hasKey("IndicatorRemarkKey")){
            old = redisCache.getCacheObject("IndicatorRemarkKey");
        }
        // 获取当前的用户
        LoginUser loginUser = SecurityUtils.getLoginUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setTitle("积分规则");
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = IpUtils.getIpAddr();
        operLog.setOperIp(ip);
        operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
        if (loginUser != null)
        {
            operLog.setOperName(loginUser.getUsername());
            SysUser currentUser = loginUser.getUser();
            if (StringUtils.isNotNull(currentUser) && StringUtils.isNotNull(currentUser.getDept()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }
        // 设置方法名称
        operLog.setMethod("edit");
        // 设置请求方式
        operLog.setRequestMethod(ServletUtils.getRequest().getMethod());

        // 处理设置注解上的参数
        String template = String.format("积分规则 ，指标备注，%s 修改为，%s",old,remark);
        operLog.setJsonResult(template);
        // 设置消耗时间
        operLog.setCostTime(0L);

        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));


        redisCache.setCacheObject("IndicatorRemarkKey", remark);
        return R.ok();
    }
}
